<?php

class Mgame extends AppModel {

    var $alias = 'Mgame';
    var $name = 'Mgame';
    var $useTable = 'mgames';
    var $belongsTo = array(
        'Catmgame' => array(
            'className' => 'Catmgame',
            'foreignKey' => 'cat_id',
            'fields' => array('Catmgame.id', 'Catmgame.title', 'Catmgame.alias')
        ),
        'MgameTechnical' => array(
            'className' => 'MgameTechnical',
            'foreignKey' => 'technical_id',
            'fields' => array('MgameTechnical.id', 'MgameTechnical.title', 'MgameTechnical.alias')
        ),   
        'MgameGroup' => array(
            'className' => 'MgameGroup',
            'foreignKey' => 'group_id',
            'fields' => array('MgameGroup.id', 'MgameGroup.title', 'MgameGroup.alias')
        ),        
    );

    function delete($id = null, $cascade = true) {
        App::import('Component', 'Upload');
        $this->id = $id;
        $upload = new UploadComponent();

        //delete thumbnail
        $thumbnail = $this->field('thumbnail');
        if (is_file(Configure::read('game_image_thumb_absolute_path') . $thumbnail) && $thumbnail != 'no_image.gif') {
            $upload->delete(Configure::read('game_image_thumb_absolute_path') . $thumbnail);
        }
        //delete flash
        $flash_path = $this->field('flash_path');
        if (is_file(Configure::read('game_flash_absolute_path') . $flash_path) && $flash_path != 'no_image.gif') {
            $upload->delete(Configure::read('game_flash_absolute_path') . $flash_path);
        }


        parent::delete($id, $cascade);
    }

    function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
        $parameters = compact('conditions');
        $this->recursive = $recursive;
        $count = $this->find('count', array_merge($parameters, $extra));
        if (isset($extra['group'])) {
            $count = $this->getAffectedRows();
        }
        return $count;
    }
}

?>
